<template>
    <div class="el-mdlist">
        <div class="el-mdlist-back" >
            <span @click="backMenu">
                <img class="el-mdlist-backIcon" src="../../../../public/img/arrow.png" alt="">
                返回主页
            </span>
        </div>
        <div class="el-mdlist-title">
            <img src="../../../../public/img/materialReceiveMini.png" alt="">
            <span>运行监控</span>
        </div>
        <div class="el-mdlist-content">
            <el-menu :default-active=show class="el-menu-vertical-demo">
               
                    <el-menu-item v-for="(item,index) in listName" :key="index" :index=item.index @click="showBj(item)">
                        <template slot="title">
                            <span>{{item.name}}</span>
                        </template>
                    </el-menu-item>
          
            </el-menu>
        </div>
    </div>
</template>
<script>
import request from "@/utils/request.js";
export default {
    name:'OperationMonitoringList',
    props:{curMenus:{type:Array},
    updateCom: {
        type: Function,
        default: null
      }},
    data(){
        return{
            listName:[],
            show:''
        }
    },
    methods:{
        showBj(item){
            this.show = String(item.index);
            item.class="active";
            
            let curMenu = this.curMenus;

            if(curMenu.length>7){
                alert("启用的菜单过多，请关闭部分菜单！");
                return;
            }
            let isLoad = false;
    
            for(let i=0;i< curMenu.length;i++){
                let menu = curMenu[i];
                if(menu.index == item.index){
                    menu.class="active";
                    isLoad = true;
                }else{
                    menu.class="none";
                }
            }
            if(!isLoad){
                curMenu.push(item);
            }
            
            console.log(this.curMenus);
            this.updateCom();
        },
        setShowMenu(item){
            this.show = item.index;
        },
        backMenu(){
            this.$router.push('/menu')
        }

    },
    mounted(){
        this.show = sessionStorage.getItem('listNumber')
        this.$nextTick(function () {
            const that = this;
            // yebo 仅在整个视图都被渲染之后才会运行的代码 
            console.log("======111====");
            request.post("/system/query/queryMenu",{"grade":"2","belongTo":"fj_yxjk"}).then(function(res){
                console.log("res",res);
                //this.listName.push
            //  this.listName = [];
                that.listName=res.data;
            })
        })
        
    },
    beforeDestroy(){
        sessionStorage.removeItem('listNumber')
    }
}

</script>
<style scoped>
.el-mdlist {
    width: 100%;
    height: 100%;
}
.el-mdlist-back {
    width: 80%;
    margin-left: 10%;
    color: #DCEFFB;
    padding-bottom: 15px;
    border-bottom: 1px solid #FFFFFF;
    cursor: pointer;
}
.el-mdlist-backIcon {
    height: 14px;
}
.el-mdlist-title {
    color: #DCEFFB;
    padding-top: 10px;
    text-align: center;
}
.el-mdlist-title span {
    vertical-align: 45%;
}
.el-menu {
    background-color: transparent;
    border: none;
}
.el-mdlist-content {
    margin-top: 15px;
    text-align: center;
}
.el-menu-item {
    padding-top: 10px;
    padding-bottom: 10px;
    height: 40px;
    line-height: 20px;
    color: #DCEFFB;
}
.el-menu-item:hover {
    background-color: #2BBECF;
}
.el-menu-item.is-active {
    background-color: #2BBECF;
    color: #FFFFFF;
}
</style>